/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package streams;

import com.google.api.translate.Language;
import com.google.api.translate.Translate;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;



/**
 *
 * @author Educacionit
 */
public class Traductor {

    public void traducir(String nombre1,String nombre2){
        File arch1 = new File(nombre1);
        File arch2 = new File(nombre2);

        FileReader in = null;
        BufferedReader bin = null;
        FileWriter out = null;
        BufferedWriter bout = null ;
        try{
            in = new FileReader(arch1);
            bin = new BufferedReader(in);
            out = new FileWriter(arch2);
            bout = new BufferedWriter(out);
            // Set the HTTP referrer to your website address.
            Translate.setHttpReferrer("http://educacionit.com.ar");
            String textoViejo ="";

            while(bin.ready())
                textoViejo += bin.readLine();

            String textoNuevo = Translate.execute(textoViejo,Language.SPANISH, Language.ENGLISH);

            bout.write(textoNuevo);
            
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            try{
                bin.close();

            }catch(Exception e){
                e.printStackTrace();
            }
            try{

                bout.close();
            }catch(Exception e){
                e.printStackTrace();
            }
            try{
                in.close();
            }catch(Exception e){
                e.printStackTrace();
            }
            try{
                out.close();

            }catch(Exception e){
                e.printStackTrace();
            }

        }


}

}
